<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>发货托运单打印</title>
		<script src='${ctxPath}/assets/mui/js/jquery-1.11.3.js'></script>
	</head>
	<style>
		p{
			font-size: 12px;
			margin: 0;
		}
		.button{
			background-color: #A6A6A6; color: black; /* Green */
		    border: none;
		    color: white;
		    padding: 10px 32px;
		    text-align: center;
		    text-decoration: none;
		    display: inline-block;
		    font-size: 14px;
    	}
	</style>
	<body>
		<div style="width: 100%;">
			<button id="button" class="button" onclick="doPrint()">打印</button>
		</div>
		<div id="big" style="width: 100%;">
		</div>
		<script type="text/jscript">
			//通过URL 获取参数
			function GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			};
			var dispatchNumber = GetQueryString("dispatchNumber");
			var getUnitid = GetQueryString("getUnitid");
			var getLocationid = GetQueryString("getLocationid");
			var now = new Date()
			var year = now.getFullYear()
			var month = now.getMonth()+1
			var day = now.getDate()
			var hour = now.getHours()
			var m = now.getMinutes()
			var s = now.getSeconds()
			var newdate = year+"-"+month+"-"+day+" "+hour+":"+m+":"+s
			function findtou(aa,param){
				return '<div id="-title" style="width: 100%; height: 25px;margin-top: 10px;">'+
					'<p style="float: left; width: 60%;height: 2px;text-align: right;font-size: 18px;font-weight: 600;">山东泉林本色有限公司销售交货单</p>'+
					'<p style="float: right; width: 40%;height: 2px;text-align: right;">'+aa+'  打印时间：'+newdate+'</p>'+
				'</div>'+
				'<div id="-title-l" style="width: 100%; height: 20px;">'+
					'<p style="float: left; width: 35%;height: 2px;">收货单位：'+param.getUnit+'</p>'+
					'<p style="float: right;width: 65%; text-align: right;height: 2px;">收货地址：'+param.getLocation+'</p>'+
				'</div>'+
				'<div id="-title-l" style="width: 100%; height: 20px;">'+
					'<p style="float: left; width: 50%;height: 2px;">收货人：'+param.getPeople+'</p>'+
					'<p style="float: right; width: 50%;height: 2px;text-align: right;">收货电话：'+param.getTel+'</p>'+
				'</div>';
			}
			function findstorageOuttitle(data,customerOrder,kilometer,nodes){
				return	'<div id="order-title" style="width: 100%;height: 40px;">'+
					'<div id="order-title-1" style="width: 100%;">'+
						'<p style="float: left; width: 30%;font-size: 13px;">单据编号：'+customerOrder+'</p>'+
						'<p style="float: left; width: 20%;">车牌号：'+data.carnumber+'</p>'+
						'<p style="float: left; width: 20%;">距离公里数：'+kilometer+'</p>'+
						'<p style="float: left; width: 30%;">备注：'+nodes+'</p>'+
					'</div>'+
				'</div>';
			}
			load();
			function load(){
				var big = $("#big");
				//big.append(storageOutmsg);
				$.ajax({
				    url:'${ctxPath}/tDispatch/getPrintReceipt',
				    type:'post',
				    dataType:'json',
				    data:{"dispatchNumber":dispatchNumber,"getUnitid":getUnitid,"getLocationid":getLocationid},
				    success:function(data){
				        if(data!=null){
					 		var storageOutbottom = '<div id="order-title" style="width: 100%;height: 40px;">'+
														'<div id="order-title-1" style="width: 100%;">'+
															'<p style="float: left; width: 25%;">发货人：</p>'+
															'<p style="float: left; width: 25%;">制单人：'+data.zhidanren+'</p>'+
															'<p style="float: right; width: 25%;">签收人：</p>'+
															'<p style="float: right; width: 25%;">收货日期：</p>'+
														'</div>'+
														'<div id="order-title-2" style="width: 100%;">'+
															'<p style="float: left; width: 100%;">注：白色为存根联		红色出门联			黄色客户联			蓝色回单联			绿色财务联</p>'+
														'</div>'+
													'</div>';
							$.ajax({
								url:'${ctxPath}/tDispatch/getprintlist',
								type:'post',
								dataType:'json',
               					async:false,
               				    data:{"dispatchNumber":dispatchNumber,"getUnitid":getUnitid,"getLocationid":getLocationid},
								success:function(data1){
									if(data1.length>0){
										$.each(data1,function(key,value){
											var customerOrder = '';
											var kilometer = '';
											var nodes = '';
											var ncont = 0.0;
											var vcont = 0.0;
											var mcont = 0.0;
											var storageOutdata = '<div id="order-date" style="width: 100%;height: 300px;">'+
															'<table id="order-table" style="width: 100%; font-size: 12px;" border="1px solid" cellpadding="0" cellspacing="0">'+
																'<thead>'+
																	'<th>货号</th>'+
																	'<th>包装</th>'+
																	'<th>数量</th>'+
																	'<th>体积</th>'+
																	'<th>单价</th>'+
																	'<th>金额</th>'+
																	'<th>批次</th>'+
																	'<th>备注</th>'+
																'</thead>'+
																'<tbody>';
											$.each(value.listd,function(key1,value1){
												customerOrder = value1.customerOrder;
												kilometer = value1.kilometer;
												nodes = value1.nodes;
												ncont += value1.tooDeployNum*1;
												vcont += value1.tooDeployVolume*1;
												mcont += value1.transportMoney*1;
												storageOutdata += '<tr>'+
																		'<td>'+value1.goodsNo+'</td>'+
																		'<td>'+value1.goodsPacking+'</td>'+
																		'<td>'+value1.tooDeployNum+'</td>'+
																		'<td>'+value1.tooDeployVolume+'</td>'+
																		'<td>'+value1.unitprice+'</td>'+
																		'<td>'+value1.transportMoney+'</td>'+
																		'<td>'+value1.batchnumber+'</td>'+
																		'<td></td>'+
																	'</tr>';
											});
											storageOutdata += '<tr>'+
																	'<td></td>'+
																	'<td>小计：</td>'+
																	'<td>'+Math.round(ncont * 100) / 100+'</td>'+
																	'<td>'+Math.round(vcont * 100) / 100+'</td>'+
																	'<td></td>'+
																	'<td>'+Math.round(mcont * 100) / 100+'</td>'+
																	'<td></td>'+
																	'<td></td>'+
																'</tr>';
											storageOutdata += '<tr>'+
																	'<td></td>'+
																	'<td>合计：</td>'+
																	'<td>'+data.tooNum+'</td>'+
																	'<td>'+data.toovolume+'</td>'+
																	'<td></td>'+
																	'<td>'+data.toomoney+'</td>'+
																	'<td></td>'+
																	'<td></td>'+
																'</tr>';
											storageOutdata += '</tbody>'+
														'</table>'+
													'</div>';
											var tou = findtou('第'+(key+1)+'页  '+'共'+data1.length+'页',data)
											var storageOuttitle = findstorageOuttitle(data,customerOrder,kilometer,nodes)
											big.append(tou+storageOuttitle+storageOutdata+storageOutbottom);
										});
									}else{
							 			alert("未查询到派车明细!");
									}
								},
								error:function(data){
									alert("查询派车明细异常!");
								}
							});
				 		}else{
				 			alert("未查询到派车信息!");
				 		}
				    },
				    error: function(data){
						alert("查询派车异常!");
				    }
				});
			};
			//打印
			function doPrint() {
		        bdhtml = window.document.body.innerHTML;
		        phtnl = window.document.getElementById("big").innerHTML;
		        window.document.body.innerHTML = phtnl; //把需要打印的指定内容赋给big
		        window.print(); //调用浏览器的打印功能打印指定区域
		        window.document.body.innerHTML=bdhtml; // 最后还原页面
		    };
		    //打印的回调
		    var beforePrint = function() {
		        //打印前调用
		    };
		    var afterPrint = function() {
		        //打印后调用
            	var Indexs = parent.layer.getFrameIndex(window.name);
                parent.layer.close(Indexs);
		    };
		    if (window.matchMedia) {
		        var mediaQueryList = window.matchMedia('print');
		        mediaQueryList.addListener(function(mql) {
		            if (mql.matches) {
		                beforePrint();
		            } else {
		                afterPrint();
		            }
		        });
		    }
		</script>
	</body>
</html>